package com.sikadwafastdaisfondturbo.pretloan.ui.permission

import android.Manifest
import com.sikadwafastdaisfondturbo.pretloan.R
import com.sikadwafastdaisfondturbo.pretloan.app.App
import org.json.JSONArray
import org.json.JSONObject

/**
 * Sikadwa
 * @Author wwdeng
 * @CreateTime: 2024/4/16 17:04
 * @Annotation：权限配置
 */
object PermissionConfig {

    /**
     * 根据权限类型匹配对应的图标
     */
    fun getPermissionIcon(permission: String): Int{
        var resId = R.mipmap.img_permission_sms
        when(permission){
            Manifest.permission.READ_SMS -> {
                resId = R.mipmap.img_permission_sms
            }
            Manifest.permission.READ_PHONE_STATE -> {
                resId = R.mipmap.img_permission_phonestatus
            }
            App.instance().getString(R.string.permission_app_list_title) -> {
                resId = R.mipmap.img_permission_applist
            }
        }
        return resId
    }

    /**
     * 根据权限类型匹配对应的名称
     */
    fun getPermissionTitle(permission: String): String{
        var title = ""
        when(permission){
            Manifest.permission.READ_SMS -> {
                title = App.instance().getString(R.string.permission_sms_title)
            }
            Manifest.permission.READ_PHONE_STATE -> {
                title = App.instance().getString(R.string.permission_phone_state_title)
            }
            App.instance().getString(R.string.permission_app_list_title) -> {
                title = App.instance().getString(R.string.permission_app_list_title)
            }
        }
        return title
    }

    fun getPermissionItem(permission: String): JSONObject{
        var item = JSONObject()
        item.put("permission",permission)
        item.put("isDeny",false)
        item.put("isMust",true)
        when(permission){
            Manifest.permission.READ_SMS -> {
                item.put("icon",R.mipmap.img_permission_sms)
                item.put("title",App.instance().getString(R.string.permission_sms_title))

                val msgArray = JSONArray()
                val obj1 = JSONObject()
                obj1.put("title",App.instance().getString(R.string.permission_sms_title))
                obj1.put("des",App.instance().getString(R.string.permission_sms_des1))
                msgArray.put(obj1)

                val obj2 = JSONObject()
                obj2.put("title",App.instance().getString(R.string.permission_sms_title))
                obj2.put("des",App.instance().getString(R.string.permission_sms_des2))
                msgArray.put(obj2)

                val obj3 = JSONObject()
                obj3.put("title",App.instance().getString(R.string.permission_sms_title))
                obj3.put("des",App.instance().getString(R.string.permission_sms_des3))
                msgArray.put(obj3)
                item.put("msgList",msgArray)
            }
            Manifest.permission.READ_PHONE_STATE -> {
                item.put("icon",R.mipmap.img_permission_phonestatus)
                item.put("title",App.instance().getString(R.string.permission_phone_state_title))

                val msgArray = JSONArray()
                val obj1 = JSONObject()
                obj1.put("title",App.instance().getString(R.string.permission_phone_state_title))
                obj1.put("des",App.instance().getString(R.string.permission_phone_state_des1))
                msgArray.put(obj1)

                val obj2 = JSONObject()
                obj2.put("title",App.instance().getString(R.string.permission_phone_state_title))
                obj2.put("des",App.instance().getString(R.string.permission_phone_state_des2))
                msgArray.put(obj2)

                val obj3 = JSONObject()
                obj3.put("title",App.instance().getString(R.string.permission_phone_state_title))
                obj3.put("des",App.instance().getString(R.string.permission_phone_state_des3))
                msgArray.put(obj3)
                item.put("msgList",msgArray)
            }
            App.instance().getString(R.string.permission_app_list_title) -> {
                item.put("icon",R.mipmap.img_permission_applist)
                item.put("title",App.instance().getString(R.string.permission_app_list_title))
                item.put("isAgree",false)
                item.put("isMust",false)
                item.put("isClick",false)//是否点击 拒绝 || 同意

                val msgArray = JSONArray()
                val obj1 = JSONObject()
                obj1.put("title",App.instance().getString(R.string.permission_app_list_title))
                obj1.put("des",App.instance().getString(R.string.permission_app_list_des1))
                msgArray.put(obj1)

                val obj2 = JSONObject()
                obj2.put("title",App.instance().getString(R.string.permission_app_list_title))
                obj2.put("des",App.instance().getString(R.string.permission_app_list_des2))
                msgArray.put(obj2)

                val obj3 = JSONObject()
                obj3.put("title",App.instance().getString(R.string.permission_app_list_title))
                obj3.put("des",App.instance().getString(R.string.permission_app_list_des3))
                msgArray.put(obj3)
                item.put("msgList",msgArray)
            }
        }
        return item
    }
}